#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;

#endregion

namespace BusinessNuke.ImportBusiness.Web.Categories.Controls
{
    public partial class FilterControl : UserControl
    {
        public FilterControl()
        {
            InitializeComponent();

        }

        public string GetConditions()
        {
            List<string> lstConditions = new List<string>();
            foreach (var filterControl in pnlConditions.Controls)
            {
                FilterItemControl filter = filterControl as FilterItemControl;
                string filterResult = filter.GetResult();
                if (!string.IsNullOrEmpty(filterResult))
                {
                    lstConditions.Add(filterResult);
                }
            }

            ConditionResult = string.Join(" AND ", lstConditions);
            return ConditionResult;
        }

        public string ConditionResult { get; set; }

        public event EventHandler SearchClick;
        public event EventHandler ResetClick;

        private void btnSearch_Click(object sender, EventArgs e)
        {
            GetConditions();

            if (SearchClick != null)
            {
                SearchClick(sender, e);
            }
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            filterFirst.SetDefault();
            filterSecond.Reset();
            filterThird.Reset();
            filterFourth.Reset();

            ConditionResult = filterFirst.GetResult();

            if (ResetClick != null)
            {
                ResetClick(sender, e);
            }
        }

        private void FilterControl_Load(object sender, EventArgs e)
        {
            filterFirst.SetDefault();
            filterSecond.Reset();
            filterThird.Reset();
            filterFourth.Reset();
        }
    }
}